﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Web;
using StudentWeb.DAL;
using StudentWeb.Model;
using StudentWeb.Common;

namespace StudentWeb.BLL
{
    public class TravelNotesBO
    {
        #region 游记信息 全部记录
        public IResult GetNotesList()
        {
            var list = new TravelNotesDataDAO().GetList();
            return new DataResult(list);
        }
        #endregion
        #region 游记信息 单条记录
        public IResult GetNotesInfo(int NoteID)
        {
            var record = new TravelNotesDataDAO().GetInfo(NoteID);
            return new DataResult(record);
        }
        #endregion
        #region 游记信息 添加
        public bool InsertNotesInfo(dynamic data)
        {
            var user = new TravelNotesData()
            {
                TouristID = data.TouristID,
                Title = data.Title,
                Content = data.Content,
                PublishDate = data.PublishDate,
                Views = data.Views,
                Likes = data.Likes
            };
            var result = new TravelNotesDataDAO().Insert(user);
            return result > 0;
        }
        #endregion
        #region 游记信息 修改
        public bool UpdateNotesInfo(dynamic data)
        {
            int NoteID = data.NoteID;
            var record = new TravelNotesDataDAO().GetInfo(NoteID);
            record.TouristID = data.TouristID;
            record.Title = data.Title;
            record.Content = data.Content;
            record.PublishDate = data.PublishDate;
            record.Views = data.Views;
            record.Likes = data.Likes;
            var result = new TravelNotesDataDAO().Update(record);
            return result > 0;
        }
        #endregion
        #region 游记信息 删除
        public IResult DeleteNotesInfo(int NoteID)
        {
            var res = new TravelNotesDataDAO().Delete(NoteID);
            if (res > 0)
            {
                return new Result(ResultCode.Success, "删除成功");
            }
            else
            {
                return new Result(ResultCode.Fail, "删除失败");
            }
        }
        #endregion
        #region 游记信息 分页列表
        public IResult PageNotesList(int pageIndex, int pageSize, string wc = null)
        {
            var list = new TravelNotesDataDAO().GetList(pageIndex, pageSize, wc);
            return new DataResult(list);
        }
        #endregion
    }
}
